<%@ page language="java" import="java.util.*,ms.platform.system.model.*"
	pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE html>
<html>
<head>
<base href="<%=basePath%>">
<title>角色列表</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<link rel="stylesheet" type="text/css" href="<%=basePath%>js/bootstrap-3.3.6/dist/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="<%=basePath%>css/bootstrapValidator.css" />
<link rel="stylesheet" type="text/css" href="<%=basePath%>css/mydialog.css" />
<link rel="stylesheet" type="text/css" href="<%=basePath%>css/style.css" />
<script src="<%=basePath %>js/common/jquery-2.1.0.js" type="text/javascript" charset="utf-8"></script>
<script src="<%=basePath %>js/rem.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript"src="<%=basePath%>js/common/dialog.3.1.min.js"></script>
<script type="text/javascript" src="<%=basePath %>js/bootstrap-3.3.6/dist/js/bootstrap.min.js" charset="utf-8"></script>
<script type="text/javascript" src="<%=basePath%>js/delete.js"></script>
<script type="text/javascript">
		$(document).ready(function(){
			//根据id禁用/启用角色
			$("span[name='disabledRole']").click(function(){
			    var btn=$(this);
				var id=$(this).parent().attr("id");
				var isUsed=$(this).attr("isUsed");
	           $.ajax({            
	                  type:"post",
	                  url:"<%=path%>/system/role/disabledRole", 
	                  data:"id="+id+"&isUsed="+isUsed,  
	                  dataType:"json",
	                  success:function(data) {
	                	if(data.message != undefined){
	                	  Dialog({
		  		                "msg": '<div class="D_alert">'+data.message+'</div>',
		  		                "title": "提示",
		  		                "showButtons": true,
		  		                "cancelButton": false,
		  		                "onComplete": function() {
		  		                	grayScreen.style.display="none";
		  		                	window.location.reload();
		  		                }
		  		          });
						if(isUsed=="1"){
							$("#"+id).parent().find(".isUsedTd").html("启用");
							btn.attr("isUsed",0);
							btn.html("禁用");
						}else{
							$("#"+id).parent().find(".isUsedTd").html("<span style='color: red'>禁用</span>");
							btn.attr("isUsed",1);
							btn.html("启用");
						}
	                   }else{
	                		  window.location.reload();
	                	  }
	                	  
	                  }            
	            });   
			});
			
			//获取删除角色的ID 添加到隐藏域
			$("span[name='deleteRole']").click(function(){
			       var id=$(this).parent().attr("id");
			       $(".hiddenId").val(id);
				});
			//删除角色
			$("#deleteDict").on("click",function(e){
				var id=$(".hiddenId").val();
				deleteList.hiddenId("<%=path%>/system/role/deleteRole","<%=path%>/system/role/list",("roleId="+id));
				
			}); 
			//根据id跳转到编辑页面
			$("span[name='editRole']").click(function(){
		       var id=$(this).parent().attr("id");
		       window.location.href="<%=path%>/system/role/toEdit?id="+id;;
			});
			
			//跳转到添加页面
			$(".addRole").click(function(){
				window.location.href="<%=path%>/system/role/toAddRole";
			});
			
			//清空搜索条件
			$(".clearForm").click(function(){
				$("#queryForm").find("input").val("");
			});
			
			//提交表单
			$(".queryForm").click(function(){
				 var data=$("#queryForm").serialize();
					window.location.href="<%=path%>/system/role/list?"+data;
			});
			
			
			$(".queryRole").click(function(){
				 var data=$("#queryForm").serialize();
				window.location.href="<%=path%>/system/role/list?"+data;
			});
			
			$("input[name='resourceCheckbox']").click(function() {
				$(this).attr("operation","operation");
			});
			
			//分配权限
			$("span[name='toAllotResource']").click(function(){
				var isUsed = $(this).parent().find('span').eq(0).attr('isUsed');
				var id=$(this).parent().attr("id");
				if(isUsed==1){
					showMessage("当前角色状态为禁用，请点击‘启用’状态");
				}else{
				window.location.href="<%=path%>/system/resource/toAllotResource?roleId="+id;
					
				}
			});
		});
    </script>
</head>
<body>
	<div id="index-hav2">
		<div class="index-hav-right" id="index-hav-right-clear">
			<div class="row">
				<div class="col-md-9">
					<span id="icon-house"></span>
					<span id="arrows-left">首页</span>
					<span id="arrows-left">></span><span>系统管理</span><span id="arrows-left">></span><span>角色管理</span>
				</div>
				<div class="bank-box">
					<div class="lianlian platform">
						<div class="col-md-12">
							<form role="form" id="queryForm" method="post">
								<table class="textTable">
									<tr>
										<td class="platform-start">名称:</td>
										<th class="">
											<input type="text" class="Wdate form-control input-sm" name="roleName" value="${map['roleName'] }">
										</th>
										
									</tr>
								</table>
								<ul class="textBtn">
								    <li class="">
										<button class="search-form-btn-s btn btn-primary btn-sm">查询</button>
										<button type="button" class="clearForm btn btn-primary btn-sm">重置</button>
										<button type="button" class="addRole btn btn-primary btn-sm">添加</button>
									</li>
								</ul>
							</form>

							<table class="control-tatle table table-striped table-bordered table-hover" action="<%=path%>/system/role/list">
								<thead class="financing-thead">
									<tr>
										<th>序号</th>
										<th>名称</th>
										<th>类型</th>
										<th>状态</th>
										<th>创建时间</th>
										<th>修改时间</th>
										<!-- <th>备注</th> -->
										<th>操作</th>
									</tr>
								</thead>
								<tbody>
								<c:if test="${not empty list}">
									<c:forEach items="${list }" var="role" varStatus="s">
										<tr>
											<td>${s.index+1 }</td>
											<td>${role.roleName }</td>
											<td>
												<c:if test="${role.type==1}">管理员</c:if>
												<c:if test="${role.type==2}">普通用户</c:if>
											</td>
											<td class="isUsedTd">
												<c:if test="${role.isUsed==1 }">启用</c:if> 
			                          			<c:if test="${role.isUsed==0 || role.isUsed==2 }">
													<span style="color: red">禁用</span>
												</c:if>
											</td>
											<td><fmt:formatDate value="${role.createTime }" pattern="yyyy-MM-dd HH:mm:ss" /></td>
											<td><fmt:formatDate value="${role.updateTime }" pattern="yyyy-MM-dd HH:mm:ss" /></td>
											<%-- <td>${role.comment }</td> --%>
											<td id="${role.id }">
												<c:if test="${role.isUsed==1 }">
													<span name="disabledRole" class="span1" isUsed=0>禁用</span>
												</c:if> 
												<c:if test="${role.isUsed==0 }">
													<span name="disabledRole" class="span1" isUsed=1>启用</span>
												</c:if> 
												<span name="editRole" class="span1">编辑</span>
												<span name="deleteRole" data-toggle='modal' data-target='#bxModal' class="span1">删除</span> 
												<span name="toAllotResource" class="span1">分配权限</span>
											</td>
											<input type="hidden" class="hiddenId" value="">
										</tr>
									</c:forEach>
									</c:if>
									<c:if test="${empty list}">
										<tr>
											<td colspan="10"><label class="control-label text-center">无记录</label></td>
										</tr>
									</c:if>
								</tbody>
								<tr style="background: #f8f8f8">
									<td colspan="10"><jsp:include flush="false" page="/WEB-INF/jsp/page.jsp"></jsp:include></td>
								</tr>
							</table>
						</div>
						<!-- 删除弹框 start -->
						<div class="modal fade" id="bxModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" >
						     <div class="modal-dialog modal-tbxb" style=" top:50%; margin-top:-5%;">
						          <div class="modal-content" >
						               <div class="modal-header">
											<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
											<h4 class="modal-title">提示</h4>
									   </div>
									   <div class="modal-body">
									       <div class="form-group financialRisk" style="text-align:center;">
												是否确认删除？
								          </div>
								          <ul class="col-btn-12">
											<li>
												<button class="btn-primary btn" id="deleteDict" data-dismiss="modal" aria-hidden="true">确认</button>
												<button type="button" class="btn-default btn" data-dismiss="modal" aria-hidden="true">取消</button>
											</li>
										</ul>
									   </div>
						          </div>
						     </div>
						</div>
						<!-- 删除弹框 end -->
					</div>
				</div>
			</div>
		</div>
	</div>
	<div id="gray-screen"></div>
</body>
</html>
